<?php
class menu_edit extends SClass {


    public function process() {
        try {
            if ($this->getControlValue('ok')) {
                ServiceUtils::GetFactory()->getHmenuService()->editHmenu(
                          $this->getArgument('id'),
                       $this->getControlValue('name'),
                         $this->getControlValue('url'),
                        $this->getControlValue('position'),
                        $this->getControlValue('parentid')
                     /*    '/one/', 0,null*/

                );

                $this->assign('message', 'ok');
           } else {
                $post = ServiceUtils::GetFactory()->getHmenuService()->getHmenuById(
                        $this->getArgument('id')
                        );

                $this->setControlValue('name', $post->getName());
                $this->setControlValue('url', $post->getURL());
                $this->setControlValue('position', $post->getPosition());
         
                $post = ServiceUtils::GetFactory()->getHmenuService()->getHmenuTopLevel();
                $a = array();
                while ($x = $post->getNext()) {
                    $a[] = array(
                        'id' => $x->getId(),
                        'name' => $x->getName()
                    );
                }
                $this->assign('postArray', $a);

            }
        } catch (ServiceUtils_Exception $e) {
            $this->assign('errors', $e->getErrors());
        }
    }


}